package com;

import com.pojo.Employee;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import util.MybatisUtils;

public class EmployeeTest {
    @Test
    public void getEmployeeTest() {
        SqlSession sqlSession = MybatisUtils.getSession();
        Employee employee = sqlSession.selectOne("com.mapper.EmployeeMapper.selectByPrimaryKey", 1L);
        System.out.println(employee);
    }

    @Test
    public void addEmployeeTest() {
        SqlSession sqlSession = MybatisUtils.getSession();
        Employee employee = new Employee();
        employee.setName("周清华");
        employee.setAge("18");
        employee.setPosition("员工");
        int a = sqlSession.insert("com.mapper.EmployeeMapper.insert", employee);
        System.out.println(a);
        sqlSession.commit();// 提交事务
        sqlSession.close();// 关闭连接
    }

    @Test
    public void updateEmployeeTest() {
        SqlSession sqlSession = MybatisUtils.getSession();
        Employee employee = new Employee();
        employee.setName("周小明");
        employee.setAge("18");
        employee.setPosition("员工");
        int a = sqlSession.update("com.mapper.EmployeeMapper.updateByPrimaryKey", employee);
        System.out.println(a);
        sqlSession.commit();// 提交事务
        sqlSession.close();// 关闭连接
    }
    @Test
    public void deleteEmployeeTest() {
        SqlSession sqlSession = MybatisUtils.getSession();
        int a = sqlSession.delete("com.mapper.EmployeeMapper.deleteByPrimaryKey", 1L);
        System.out.println(a);
        sqlSession.commit();// 提交事务
        sqlSession.close();// 关闭连接
    }
}
